package com.sdtele.tta.operation;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sdtele.tta.dac.Dac;
import com.sdtele.tta.models.JsonRequest;
import com.sdtele.tta.models.JsonResponse;
import com.sdtele.tta.models.User;
import com.sdtele.tta.models.VoteTask;


public class OperationGetVoteList extends Operation {
	public JsonResponse handle(JsonRequest jsonRequest) {
		System.out.println("OperationLogin:req="+jsonRequest);
		JsonResponse jres = new JsonResponse();
		User user=(User) request.getSession().getAttribute("user");
		List< Map<String,Object>> voteList=new ArrayList< Map<String,Object>>();
		if(user!=null)
		{
			List<VoteTask> voteTaskList = Dac.getInstance().getVoteTask(user.getId());
			if( voteTaskList!=null) {
			for(VoteTask vt:voteTaskList) {
				 Map<String,Object> voteMap=new  HashMap<String,Object> ();
				 voteMap.put("voteTask", vt.ToVoteTaskOut());
				 User owner =Dac.getInstance().getUser(vt.getOwnerId());
				 System.out.println(owner);
				 voteMap.put("owner", owner);
				 voteList.add(voteMap);
				 
			}
			if(voteList.size()>0) {
			jres.setStatus(0);
			jres.setMessage("用户:"+user.getName()+"投票任务列表");
			jres.setEntity(voteList);
			}else {
				jres.setStatus(1);
				jres.setMessage("返回任务列表失败");
			}
			}else {
				jres.setStatus(0);
				jres.setMessage("用户:"+user.getName()+"无投票任务");
			}
		}else
		{
			jres.setStatus(1);
			jres.setMessage("用户登录失效,请重新登录");
		}
		return jres;
	}
   
}